<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 <div id="dialog-message">
	<div id="questionInfo"></div>
 </div>
 <script>
 (function(){
	 var juanId ="${param.note}";//因为哪边的后台查询把juanId放在的了这个里面，sql重用的问题
	 var userId ="${param.string2}"; 
	 var flag ="${param.f}";
 
	 var ctime = (new Date()).Format("yyyy-MM-dd hh:mm:ss");
	 function loadPaperInfo(){
		  if(juanId==""){
			  return;
		  }
		  var url ="${pageContext.request.contextPath}/edu/sys_TestPaperAction.do?method=getTest_PaperQuestionInfo";
		  $.ajax({
			   type: "POST",
			   url: url,
			   data: {table_id:juanId,userId:userId},
			   dataType:'json',
			   success: function(msg){ 
				 if(msg && msg[0].list){
					 var list = msg[0].list;
					 if(list && list.length>0){
						 for(var i =0;i<list.length;i++){
							 var question = list[i];
							 var type="主观";
							 if(question.type==1){
								   type="客观";
							 }
							 var table=$('<table class="table table-striped table-hover table-bordered"></table>');
							 var tr1='<tr><td width="200px">标题</td>><td>'+question.title+'</td></tr>';
							 var tr21='<tr><td>内容</td>><td>'+question.content+'</td></tr>';
							 var tr2='<tr><td>类型</td>><td>'+type+'</td></tr>';
							 var tr3='<tr><td>分值</td>><td>'+question.fen+'</td></tr>'; 
							 var tr4='<tr><td>答案</td>><td><textarea id="note" name="note" table_id="'+question.table_id+'" maxlength="300" class="autosize-transition form-control">'+question.string1+'</textarea></td></tr>';
							 if(flag=="1"){
								 tr4='<tr><td>答案</td>><td><textarea disabled="disabled"  id="note" name="note" table_id="'+question.table_id+'" maxlength="300" class="autosize-transition form-control">'+question.string1+'</textarea></td></tr>';
								  if(question.string2 && question.string2=="1" && question.type=="1"){
									    var tr6='<tr><td>得分【系统自动批阅】</td>><td><input type="text" table_id="'+question.table_id+'" disabled="disabled" value="'+question.string3+'"></td></tr>'; 
								  }else{
									    var tr6='<tr><td>得分</td>><td><input type="text" value="'+question.string3+'" table_id="'+question.table_id+'"></td></tr>'; 
								  }
								
							 } 
							var tr5='<tr><td></td><td><button class="btn btn-primary" table_id="'+question.table_id+'" fen="'+question.fen+'">确认</button></td></tr>';
							
							 table.append(tr1); 
							 table.append(tr21); 
							 table.append(tr2); 
							 table.append(tr3); 
							 table.append(tr4); 
							 if(flag=="1"){
							 	 table.append(tr6); 
							 }
							 table.append(tr5); 
							 $("#questionInfo").append(table);
							 $("button[table_id ="+question.table_id+"]").click(function(){
								 var table_id =$(this).attr("table_id");
								  var fen =$(this).attr("fen");
								 if(flag=="1"){
									  dafen(table_id,juanId,fen); //表示是老师给分 
								 }else{
									 dati(table_id,juanId); //表示是学生答题
								 }
							 });
						 }
					 }
				 }
			   }
		  });
		  
	  }
	   //答题
	  function dati(table_id,juanId){ 
		  var daan = $("textarea[table_id="+table_id+"]").val();
		  var object = new Object();
		  object.table_id = table_id;
		  object.juanId=juanId;
		  object.daan = daan;
		  object.startTime=ctime;
		  object.type="0";  //表示答案是文字
		  if($.trim(daan)!=""){
			 var url ="${pageContext.request.contextPath}/edu/sys_TestPaperAction.do?method=updateQuestionValue";
			 $.ajax({
			   type: "POST",
			   url: url,
			   data:object,
			   dataType:'json',
			   success: function(msg){
					alert(msg.message);
					if(msg.code==1){
						ctime=(new Date()).Format("yyyy-MM-dd hh:mm:ss");
					}
			   }
			});
		  }else{
			  alert("答案不能为空");
		  } 
	  };
	   //打分
	  function dafen(table_id,juanId,fen){ 
		  var dafen = $("input[table_id="+table_id+"]").val();
		  var object = new Object();
		  object.table_id = table_id;
		  object.juanId=juanId;   
		  object.userId=userId;
		  object.qValue=dafen;
		  
		  if(dafen=="" ||dafen.length<=0){
			  alert("没有评分");
			  return;
		  } 
		  var b =isNumber(object.qValue);
		  
		  if(b==false){
			  alert("只能输入数字");
			  return;
		  }
		  if(fen<parseInt(object.qValue)){
			   alert("不能大于题分值");
			   return;
		  } 
			 var url ="${pageContext.request.contextPath}/edu/sys_TestPaperAction.do?method=updateQuestionQValue";
			 $.ajax({
			   type: "POST",
			   url: url,
			   data:object,
			   dataType:'json',
			   success: function(msg){
					alert(msg.message);
					 
			   }
			});
		 
	  };
	  
	  //完成答题
	  function completTestPaper(control){
		var r=confirm("完成答题后将不能对试卷进行改动");
		if (r==false){return}; 
		var object = new Object();
		object.juanId = juanId;
		object.userId =userId;
		var url ="${pageContext.request.contextPath}/edu/sys_TestPaperAction.do?method=updateCompletTestPaper";
		 $.ajax({
		   type: "POST",
		   url: url,
		   data:object,
		   dataType:'json',
		   success: function(msg){
				alert(msg.message);
				if(msg.code==1){
					 $(control).dialog('destroy'); 
					 $("#user_include").html("");
					 window.homeWorkCheck.loadTestPaper(control);
				}
		   }
		}); 
	  };
	   //完成批改
	  function completTestPaper1(control){
		var r=confirm("完成批改后将不能对试卷进行改动");
		if (r==false){return}; 
		var object = new Object();
		object.juanId = juanId;
		object.userId =userId;
		var url ="${pageContext.request.contextPath}/edu/sys_TestPaperAction.do?method=updateTeacherCompletTestPaper";
		 $.ajax({
		   type: "POST",
		   url: url,
		   data:object,
		   dataType:'json',
		   success: function(msg){
				alert(msg.message);
				if(msg.code==1){
					 $(control).dialog('destroy'); 
					 $("#user_include").html("");
					  window.homeWorkCheck.loadTestPaper(control);
				}
		   }
		}); 
	  };
	  //只能输入数字
	function isNumber(thisValue){
		//notNull(thisValue);
		var Letters = "1234567890";
		var i;
		var c;
		for( i = 0; i < thisValue.length; i ++ )
		{
			c = thisValue.charAt(i);
			if (Letters.indexOf(c)==-1)
			{
				return 0;
			}
		}
		return 1;
	};
	  //加载题
	  $(function(){
		  loadPaperInfo();
	  });
	  window.homeWork_QuestionInfo={};
	  window.homeWork_QuestionInfo.completTestPaper=completTestPaper;
	  window.homeWork_QuestionInfo.completTestPaper1=completTestPaper1;
	  
 })();
 </script>